home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / library.n < prev    next >
Encoding:
Text File  |  1995-02-22  |  8.3 KB  |  227 lines

  1. '\"
  2. '\" Copyright (c) 1991-1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994-1995 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) library.n 1.13 95/02/22 14:37:25
  9. '
  10. .so man.macros
  11. .de UL
  12. \\$1\l'|0\(ul'\\$2
  13. ..
  14. .HS library tcl
  15. .BS
  16. .SH NAME
  17. library \- standard library of Tcl procedures
  18. .SH SYNOPSIS
  19. .nf
  20. \fBauto_execok \fIcmd\fR
  21. \fBauto_load \fIcmd\fR
  22. \fBauto_mkindex \fIdir pattern pattern ...\fR
  23. \fBauto_reset\fR
  24. \fBparray \fIarrayName\fR
  25. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  26. .fi
  27. .BE
  28.  
  29. .SH INTRODUCTION
  30. .PP
  31. Tcl includes a library of Tcl procedures for commonly-needed functions.
  32. The procedures defined in the Tcl library are generic ones suitable
  33. for use by many different applications.
  34. The location of the Tcl library is returned by the \fBinfo library\fR
  35. command.
  36. In addition to the Tcl library, each application will normally have
  37. its own library of support procedures as well;  the location of this
  38. library is normally given by the value of the \fB$\fIapp\fB_library\fR
  39. global variable, where \fIapp\fR is the name of the application.
  40. For example, the location of the Tk library is kept in the variable
  41. \fB$tk_library\fR.
  42. .PP
  43. To access the procedures in the Tcl library, an application should
  44. source the file \fBinit.tcl\fR in the library, for example with
  45. the Tcl command
  46. .DS
  47. \fBsource [info library]/init.tcl
  48. .DE
  49. This will define the \fBunknown\fR procedure and arrange for the
  50. other procedures to be loaded on-demand using the auto-load
  51. mechanism defined below.
  52.  
  53. .SH "COMMAND PROCEDURES"
  54. .PP
  55. The following procedures are provided in the Tcl library:
  56. .TP
  57. \fBauto_execok \fIcmd\fR
  58. Determines whether there is an executable file by the name \fIcmd\fR.
  59. This command examines the directories in the current search path
  60. (given by the PATH environment variable) to see if there is an
  61. executable file named \fIcmd\fR in any of those directories.
  62. If so, it returns 1;  if not it returns 0.  \fBAuto_exec\fR
  63. remembers information about previous searches in an array
  64. named \fBauto_execs\fR;  this avoids the path search in
  65. future calls for the same \fIcmd\fR.  The command \fBauto_reset\fR
  66. may be used to force \fBauto_execok\fR to forget its cached
  67. information.
  68. .TP
  69. \fBauto_load \fIcmd\fR
  70. This command attempts to load the definition for a Tcl command named
  71. \fIcmd\fR.
  72. To do this, it searches an \fIauto-load path\fR, which is a list of
  73. one or more directories.
  74. The auto-load path is given by the global variable \fB$auto_path\fR
  75. if it exists.
  76. If there is no \fB$auto_path\fR variable, then the TCLLIBPATH environment
  77. variable is used, if it exists.
  78. Otherwise the auto-load path consists of just the Tcl library directory.
  79. Within each directory in the auto-load path there must be a file
  80. \fBtclIndex\fR that describes one
  81. .VS
  82. or more commands defined in that directory
  83. and a script to evaluate to load each of the commands.
  84. The \fBtclIndex\fR file should be generated with the
  85. \fBauto_mkindex\fR command.
  86. If \fIcmd\fR is found in an index file, then the appropriate
  87. script is evaluated to create the command.
  88. .VE
  89. The \fBauto_load\fR command returns 1 if \fIcmd\fR was successfully
  90. created.
  91. The command returns 0 if there was no index entry for \fIcmd\fR
  92. or if the script didn't actually define \fIcmd\fR (e.g. because
  93. index information is out of date).
  94. If an error occurs while processing the script, then that error
  95. is returned.
  96. \fBAuto_load\fR only reads the index information once and saves it
  97. in the array \fBauto_index\fR;  future calls to \fBauto_load\fR
  98. check for \fIcmd\fR in the array rather than re-reading the index
  99. files.
  100. The cached index information may be deleted with the command
  101. \fBauto_reset\fR.
  102. This will force the next \fBauto_load\fR command to reload the
  103. index database from disk.
  104. .TP
  105. \fBauto_mkindex \fIdir pattern pattern ...\fR
  106. .VS
  107. Generates an index suitable for use by \fBauto_load\fR.
  108. The command searches \fIdir\fR for all files whose names match
  109. any of the \fIpattern\fR arguments
  110. .VE
  111. (matching is done with the \fBglob\fR command),
  112. generates an index of all the Tcl command
  113. procedures defined in all the matching files, and stores the
  114. index information in a file named \fBtclIndex\fR in \fIdir\fR.
  115. For example, the command
  116. .RS
  117. .DS
  118. \fBauto_mkindex foo *.tcl\fR
  119. .DE
  120. .LP
  121. will read all the \fB.tcl\fR files in subdirectory \fBfoo\fR
  122. and generate a new index file \fBfoo/tclIndex\fR.
  123. .PP
  124. \fBAuto_mkindex\fR parses the Tcl scripts in a relatively
  125. unsophisticated way:  if any line contains the word \fBproc\fR
  126. as its first characters then it is assumed to be a procedure
  127. definition and the next word of the line is taken as the
  128. procedure's name.
  129. Procedure definitions that don't appear in this way (e.g. they
  130. have spaces before the \fBproc\fR) will not be indexed.
  131. .RE
  132. .TP
  133. \fBauto_reset\fR
  134. Destroys all the information cached by \fBauto_execok\fR and
  135. \fBauto_load\fR.
  136. This information will be re-read from disk the next time it is
  137. needed.
  138. \fBAuto_reset\fR also deletes any procedures listed in the auto-load
  139. index, so that fresh copies of them will be loaded the next time
  140. that they're used.
  141. .TP
  142. \fBparray \fIarrayName\fR
  143. Prints on standard output the names and values of all the elements
  144. in the array \fIarrayName\fR.
  145. \fBArrayName\fR must be an array accessible to the caller of \fBparray\fR.
  146. It may be either local or global.
  147. .TP
  148. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  149. This procedure is invoked automatically by the Tcl interpreter
  150. whenever the name of a command doesn't exist.
  151. The \fBunknown\fR procedure receives as its arguments the
  152. name and arguments of the missing command.
  153. .VS
  154. \fBUnknown\fR first calls \fBauto_load\fR to load the command.
  155. .VE
  156. If this succeeds, then it executes the original command with its
  157. original arguments.
  158. If the auto-load fails then \fBunknown\fR calls \fBauto_execok\fR
  159. to see if there is an executable file by the name \fIcmd\fR.
  160. If so, it invokes the Tcl \fBexec\fR command
  161. with \fIcmd\fR and all the \fIargs\fR as arguments.
  162. If \fIcmd\fR can't be auto-executed, \fBunknown\fR checks to
  163. see if the command was invoked at top-level and outside of any
  164. script.  If so, then \fBunknown\fR takes takes two additional steps.
  165. First, it sees if \fIcmd\fR has one of the following three forms:
  166. \fB!!\fR, \fB!\fIevent\fR, or \fB^\fIold\fB^\fInew\fR?\fB^\fR?.
  167. If so, then \fBunknown\fR carries out history substitution
  168. in the same way that \fBcsh\fR would for these constructs.
  169. Second, and last, \fBunknown\fR checks to see if \fIcmd\fR is
  170. a unique abbreviation for an existing Tcl command.
  171. If so, it expands the command name and executes the command with
  172. the original arguments.
  173. If none of the above efforts has been able to execute
  174. the command, \fBunknown\fR generates an error return.
  175. If the global variable \fBauto_noload\fR is defined, then the auto-load
  176. step is skipped.
  177. If the global variable \fBauto_noexec\fR is defined then the
  178. auto-exec step is skipped.
  179. Under normal circumstances the return value from \fBunknown\fR
  180. is the return value from the command that was eventually
  181. executed.
  182.  
  183. .SH "VARIABLES"
  184. .PP
  185. The following global variables are defined or used by the procedures in
  186. the Tcl library:
  187. .TP
  188. \fBauto_execs\fR
  189. Used by \fBauto_execok\fR to record information about whether
  190. particular commands exist as executable files.
  191. .TP
  192. \fBauto_index\fR
  193. Used by \fBauto_load\fR to save the index information read from
  194. disk.
  195. .TP
  196. \fBauto_noexec\fR
  197. If set to any value, then \fBunknown\fR will not attempt to auto-exec
  198. any commands.
  199. .TP
  200. \fBauto_noload\fR
  201. If set to any value, then \fBunknown\fR will not attempt to auto-load
  202. any commands.
  203. .TP
  204. \fBauto_path\fR
  205. If set, then it must contain a valid Tcl list giving directories to
  206. search during auto-load operations.
  207. .TP
  208. \fBenv(TCL_LIBRARY)\fR
  209. If set, then it specifies the location of the directory containing
  210. library scripts (the value of this variable will be returned by
  211. the command \fBinfo library\fR).  If this variable isn't set then
  212. a default value is used.
  213. .TP
  214. \fBenv(TCLLIBPATH)\fR
  215. If set, then it must contain a valid Tcl list giving directories to
  216. search during auto-load operations.
  217. This variable is only used if \fBauto_path\fR is not defined.
  218. .TP
  219. \fBunknown_active\fR
  220. This variable is set by \fBunknown\fR to indicate that it is active.
  221. It is used to detect errors where \fBunknown\fR recurses on itself
  222. infinitely.
  223. The variable is unset before \fBunknown\fR returns.
  224.  
  225. .SH KEYWORDS
  226. auto-exec, auto-load, library, unknown
  227.